package yzbx.personalwebsite.controller;

import com.alibaba.fastjson2.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import yzbx.personalwebsite.config.ConfigData;
import yzbx.personalwebsite.entity.HotTodayEntity;
import yzbx.personalwebsite.service.impl.*;
import yzbx.personalwebsite.tool.Httptool;
import yzbx.personalwebsite.tool.RedisTool;

import java.util.List;

import static yzbx.personalwebsite.config.Constants.*;

@RestController
@RequestMapping("/GetHotToday")
public class GetHotTodayController {

    private static final Logger LOGGER = LoggerFactory.getLogger(GetHotTodayController.class);

    // 服务类
    private final GetHotTodayServiceBaidu getHotTodayServiceBaidu;
    private final GetHotTodayServiceWeibo getHotTodayServiceWeibo;
    private final GetHotTodayServiceZhihu getHotTodayServiceZhihu;
    private final GetHotTodayServiceToutiao getHotTodayServiceToutiao;
    private final GetHotTodayServiceBilibili getHotTodayServiceBilibili;
    private final GetHotTodayServiceTieba getHotTodayServiceTieba;

    @Autowired
    // Spring4.0后推荐构造器注入Bean
    public GetHotTodayController(GetHotTodayServiceBaidu getHotTodayServiceBaidu,
                                 GetHotTodayServiceWeibo getHotTodayServiceWeibo,
                                 GetHotTodayServiceZhihu getHotTodayServiceZhihu,
                                 GetHotTodayServiceToutiao getHotTodayServiceToutiao,
                                 GetHotTodayServiceBilibili getHotTodayServiceBilibili,
                                 GetHotTodayServiceTieba getHotTodayServiceTieba
    ) {
        this.getHotTodayServiceBaidu = getHotTodayServiceBaidu;
        this.getHotTodayServiceWeibo = getHotTodayServiceWeibo;
        this.getHotTodayServiceZhihu = getHotTodayServiceZhihu;
        this.getHotTodayServiceToutiao = getHotTodayServiceToutiao;
        this.getHotTodayServiceBilibili = getHotTodayServiceBilibili;
        this.getHotTodayServiceTieba = getHotTodayServiceTieba;
    }

    @RequestMapping("/baidu")
    public List<HotTodayEntity> baidu() {
        return getHotTodayServiceBaidu.GetHotToday(THEME_BAIDU, KEY_BAIDU);
    }

    @RequestMapping("/weibo")
    public List<HotTodayEntity> weibo() {
        return getHotTodayServiceWeibo.GetHotToday(THEME_WEIBO, KEY_WEIBO);
    }

    @RequestMapping("/zhihu")
    public List<HotTodayEntity> zhihu() {
        return getHotTodayServiceZhihu.GetHotToday(THEME_ZHIHU, KEY_ZHIHU);
    }

    @RequestMapping("/toutiao")
    public List<HotTodayEntity> toutiao() {
        return getHotTodayServiceToutiao.GetHotToday(THEME_TOUTIAO, KEY_TOUTIAO);
    }

    @RequestMapping("/bilibili")
    public List<HotTodayEntity> bilibili() {
        return getHotTodayServiceBilibili.GetHotToday(THEME_BILIBILI, KEY_BILIBILI);
    }

    @RequestMapping("/tieba")
    public List<HotTodayEntity> tieba() {
        return getHotTodayServiceTieba.GetHotToday(THEME_TIEBA, KEY_TIEBA);
    }

    public static void main(String[] args) {
        GetHotTodayController cc = new GetHotTodayController(
                new GetHotTodayServiceBaidu(new RedisTool(new ConfigData()), new Httptool()),
                new GetHotTodayServiceWeibo(new RedisTool(new ConfigData()), new Httptool()),
                new GetHotTodayServiceZhihu(new RedisTool(new ConfigData()), new Httptool()),
                new GetHotTodayServiceToutiao(new RedisTool(new ConfigData()), new Httptool()),
                new GetHotTodayServiceBilibili(new RedisTool(new ConfigData()), new Httptool()),
                new GetHotTodayServiceTieba(new RedisTool(new ConfigData()), new Httptool())
        );
        List<HotTodayEntity> a = cc.weibo();
        System.out.println(JSON.toJSONString(a));
    }
}
